﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HaoPeng
{
    public partial class newMachineType : Form
    {
        public newMachineType()
        {
            InitializeComponent();
        }

        private void newMachineType_Load(object sender, EventArgs e)
        {
            BindCombo();
        }

        private void BindCombo()
        {
            string sql = "select * from tree_Floor";
            try
            {
                DataTable dt = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sql).Tables[0];
                comboBox1.ValueMember = "ID";
                comboBox1.DisplayMember = "FloorName";
                comboBox1.DataSource = dt;
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("绑定设备类型combo失败：" + ex.Message);
                MessageBox.Show(ex.Message);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string sql = "insert into tree_Machine(FloorID, MachineName) values (@FloorID, @MachineName)";
            try
            {
                int result = SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sql,
                    new SqlParameter("@FloorID", comboBox1.SelectedValue),
                    new SqlParameter("@MachineName", textBox3.Text));
                MessageBox.Show("共更新了" + result + "条数据！");
                DialogResult = DialogResult.OK;
                Close();
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("新增设备类型数据失败：" + ex.Message);
                MessageBox.Show(ex.Message);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
